<template>
  <div class="myContailer">
    <el-row class="myTitleBorderBottom">
      <el-col :span="12" class="myLineHeight_40px">{{this.title}}</el-col>
      <el-col :span="12" class="myTextAlignRight">
        <el-button type="primary" class="myBgGreen" @click="add">新 增</el-button>
        <!-- <el-button type="primary" class="myBgGreen">导出Excel</el-button> -->
      </el-col>
    </el-row>
    <el-row class="myMarginTop_10px" :gutter="10">
      <el-col :span="4">
        <el-select v-model="paraTypeSelected"
          clearable
          placeholder="请选择参数类型">
          <el-option
            v-for="item in Object.keys(paraTypeList)"
            :key="paraTypeList[item]"
            :label="paraTypeList[item]"
            :value="item">
          </el-option>
        </el-select>
      </el-col>
      <el-col :span="4">
        <el-input v-model="kw" placeholder="请输入关键字"></el-input>
      </el-col>
      <el-col :span="3">
        <el-button type="primary" class="myBgGreen" @click="fuzzySearch">查 询</el-button>
      </el-col>
    </el-row>
    <el-row class="myMarginTop_10px" :gutter="10">
      <el-col :span="24">
        <el-table
          ref="multipleTable"
          :data="list"
          :border = true
          :stripe = true
          @selection-change="handleSelectionChange">
          <el-table-column
            type="selection"
            width="55">
          </el-table-column>
          <el-table-column
            type="index"
            label="序号"
             :index="indexMethod"
            width="100"
            >
          </el-table-column>
          <el-table-column
            prop="dev_para_no"
            label="参数编号"
            >
          </el-table-column>
          <el-table-column
            prop="dev_para_name"
            label="参数名称"
            >
          </el-table-column>
          <el-table-column
            prop="para_type"
            label="参数类型"
            >
            <template scope="scope">
              <span>{{scope.row.para_type| paraType}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="collect_node_name"
            label="所属采集节点"
            >
          </el-table-column>
           <el-table-column
            prop="status"
            label="状态"
            >
            <template scope="scope">
              <span>{{scope.row.status| deviceStatus}}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            width="200">
            <template scope="scope">
              <el-button @click="getDetail(scope.row.dev_para_id)" class="look" type="text" size="small">查看</el-button> |
              <el-button type="text" @click="modify(scope.row.dev_para_id)" class="modifly" size="small">编辑</el-button> 
              
            </template>
          </el-table-column>
        </el-table> 
        <div class="block">                    
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page_num"
            :page-sizes="[10, 15]"
            :page-size="page_size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div> 
      </el-col>
    </el-row>
  </div>
</template>  

<style scoped>
  .myContailer{
    background: #fff;
    padding: 10px;
  }
  .myTitleBorderBottom{
    color: #000;
    font-weight: 500;
    font-size: 16px;
    border-bottom: 1px solid #dbdbdb;
  }
  .myBgGreen{
    background: #00c2a9;
    border-color: #00c2a9;
    color: #fff;
    margin-top:2px;
  }
  .myBgGreen:hover{
    background: #33ceba;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myLineHeight_40px{
    line-height: 40px;
  }
  .myMarginTop_10px{
    margin-top: 10px;
  }
</style>

<script>
  import { getCollectParaList, paraTypeList } from '@/api/collect_para'
  export default {
     data(){
      return{
        title: '设备参数管理',
        devId: null,
        list:[],
        total: null,
        page_num: 1, //当前页码
        page_size: 15, //每页显示多少条

        kw: null,
        tipText:"暂无数据",
        showTip:false,
        lookObj:{},
        modifyNum:{},
        loading:false,

        multipleSelection: [],
        paraTypeList: paraTypeList,
        paraTypeSelected: null
      }
    },
    components: {
        
    },
    filters: {
      paraType: function(value) {
        return paraTypeList[value];
      }
    },
    created(){
      this.devId = this.$route.query.id;
      this.fetchList();
    },
    methods:{
      fetchList() {
        this.loading = true;
        let vm = this;
        let params = {
          kw: this.kw,
          para_type: this.paraTypeSelected,
          dev_id: this.devId,
          page_num: this.page_num,
          page_size: this.page_size
        }; 
        getCollectParaList(params)
        .then(response => {
          let res = response.data;
          vm.list = res.rows;
          vm.total = res.total;
          vm.page_num = res.page_num;
          vm.page_size = res.page_size;

          vm.loading = false;
        }).catch(error => {
          vm.loading = false;
        })
      },
      fuzzySearch() {
         this.fetchList();
      },
      handleSizeChange(val) {
        this.page_size = val;
        this.fetchList();
      },
      handleCurrentChange(val) {
        this.page_num = val;
        this.fetchList();
      },
      add(){
        this.$router.push({
          path:'/sbcsglComonents',
          query: {type: 'add', devId: this.devId}
        })
      },
      getDetail(paraId) {
        this.$router.push({
          path:'/sbcsglComonents',
          query: {type: 'info', paraId: paraId, devId: this.devId}
        })
      },
      modify(paraId) {                 
        this.$router.push({
          path:'/sbcsglComonents',
          query: {type: 'update', paraId: paraId, devId: this.devId}
        })
      },
      deleteData:function (data,index) {
        this.idArr.push(datas.list[index].dev_para_id);
        this.index = index;
        this.lookObj = data.list[index]
      },
      sureDelete:function(event){
     
        var pageArr = {
          page_num : this.currentPage,
          page_size : this.page_size
        }
        var arrId = {
          dev_para_ids : this.idArr.join(",")
        }
        $(".checkboxes").prop({checked:false})
        optVue.deleteSbcsData(this,this.index,Tips,pageArr,arrId);
      },
     checkT:function(item,e){
        //console.log($.inArray(item.area_id, this.idArr))
        if($(e.target).is(':checked')){
          if($.inArray(item.dev_para_id, this.idArr) < 0){

            this.idArr.push(item.dev_para_id);
          }
          
        }else{
          for(var i=0; i<this.idArr.length; i++) {
            if(this.idArr[i] == item.dev_para_id) {
              this.idArr.splice(i, 1);
              break;
            }
          }
        }
        //console.log(JSON.stringify(this.idArr)) 
        
      },
      inputFunc:function(e){
        if($.trim($(e.target).val())!=""){
          $(e.target).closest(".col-md-6").find(".errorInfor").addClass("hide");
          $(e.target).closest(".col-md-6").find("input").removeClass("errorInput");
        }
      },
      allCheck:function(e){
        if($(e.target).is(':checked')){
          for(var i=0; i<this.list.length; i++) {
            this.idArr.push(this.list[i].dev_para_id)
          }
        }else{
          this.idArr = [];
        }
          
        //console.log(JSON.stringify(this.idArr)) 
      },
      allDelete:function(event){
     
        if($(".checkboxes").is(':checked')){
          var pageArr = {
            page_num : this.page_num
          }
          if(this.idArr.length == this.list.length){
            var pageArr = {
              page_num : this.page_num-1
            }
            this.pageNum = this.pageNum-1;

          }
          
          var arrId = {
            dev_para_ids : this.idArr.join(",")
          }
          console.log(JSON.stringify(arrId)) 
          optVue.deleteRtuData(this,this.index,Tips,pageArr,arrId);
          
          this.idArr = [];
          $(".checkboxes").prop({checked:false});
          $(".group-checkable").prop({checked:false}) 
        }
        else{
          // Tips.init({
          //   type:"fail",
          //   message:"请选择要删的项",
          //   class:"on"
          // });
        }
      },
       handleSelectionChange(val) {
        this.multipleSelection = val;
        if(val.length!=0){
          for(var i = 0;i<val.length;i++){
            this.idArr.push(val[i].area_id)
          }
        }else{
          this.idArr = [];
        }
      },
      indexMethod(index) {
        return (this.page_num-1)*this.page_size + index + 1
      }

    }

  }

</script>  



